<html><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>课程浏览</title>
<link rel="stylesheet" type="text/css" th:href="@{css1/css.css}"  />
</head>
<style>
    .p{mso-fills-color: #f1f1f1;color: #f1f1f1}
    .p1{font-weight: bold}
    .p2{font-size:3px}
</style>
<body>
<div class="wrap clearfix">
<!-- left nav start -->
  <div class="index_left fl">
      <div th:align="center"><img class="u_img" width="100px" height="100px" th:src="@{${user.img_src}} "></div>
      <p class="p" style="text-align: center" th:text="${user.name}">用户名</p>
    <div class="nav">
      <ul>
        <li><a href="shouye" >首页</a></li>
        <li><a href="index" >课程浏览</a></li>
        <li><a href="list" >我的课程</a></li>
        <li><a href="show" >笔记</a></li>
        <li><a href="contact" >设置</a></li>
      </ul>
    </div>
  </div>
<!-- left nav end-->
  <div class="index_right fr">
<!--    <div class="banner"><img th:src="@{images/back.jpg}" /></div>-->
    <div class="main">
    <div class="index_show">
      <div class="title">所有课程</div>
      <div class="projects-holder clearfix">
          <div class="col-md-4 col-sm-6 fl" th:each="course:${courses}">
              <div class="project-item" >
                  <img th:src="@{${course.img_src}}" height="208">
                  <div class="project-hover">
                      <div class="inside">
                          <h5 th:id="h5" th:text="${course.name}">1</h5>
                          <p th:text="${course.intro}"></p>
                          <div>
                                  <button type="button" th:id="${course.name}" onclick="study(this)" style="float: left; width: 33%;">学习</button>
                              <button th:id="${course.name}"type="button" value="收藏" class="store" name="store1" style="float: right; width: 33%;" onclick="save_course(this)">收藏</button>
                          </div>
                      </div>
                  </div>
              </div>
              <p class="p1" th:text="${course.name}"></p>
              <p class="p2" th:text="${course.teacher}"></p>
          </div>
      </div>
      
    </div>
  </div>  

</div>  
  
</div>
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
    function save_course(self){
        // var name= $("#h5").text();
        // alert(self.getAttribute('id'));
        $.ajax({
            type:'POST',
            url:'add_ucourse',
            data:{"name":self.getAttribute('id')},
            dataType:"text",
            traditional:true,
            success:function (data) {
                alert(data);
            },
            error:function(XMLHttpRequest,textStatus,errorThrow){
                alert("收藏失败，请检查网络");
                alert(XMLHttpRequest.status);
                alert(XMLHttpRequest.readyState);
                alert(textStatus);
            }
        })
     }
    function study(self){
        // window.location.href = 'http://localhost:8080/course';
        // // var name= $("#h5").text();
        // // alert(self.getAttribute('id'));
        $.ajax({
            type:'POST',
            url:'ucourse',
            data:{"name":self.getAttribute('id'),"chapter":"第一章"},
            dataType:"text",
            traditional:true,
            success:function () {
                window.location.href = 'http://localhost:8080/course';
            },
            error:function(XMLHttpRequest,textStatus,errorThrow){
                alert("学习课程失败，请检查网络");
            }
        })
    }
</script>
</body>
</html>
